package com.nfc.webapp.module;

import java.util.Set;

import org.springframework.ldap.core.LdapTemplate;

public class SimpleSearch {

	private LdapTemplate ldapTemplate;

	@SuppressWarnings("unchecked")
	public Set getAllUsers() {

		UserAttributesMapper mapper = new UserAttributesMapper();
		return new HashSet(ldapTemplate.search("ou=users,ou=system",
				"(objectClass=person)", mapper));
	}

	public void setLdapTemplate(LdapTemplate ldapTemplate) {
		this.ldapTemplate = ldapTemplate;
	}

	public static void main(String[] args) {

		ApplicationContext context = new ClassPathXmlApplicationContext(
				"search.xml");

		SimpleSearch simpleSearch = new SimpleSearch();
		simpleSearch.setLdapTemplate(context.getBean("ldapTemplate",
				LdapTemplate.class));
		for (User user : simpleSearch.getAllUsers()) {
			System.out.println(user);
		}
	}

}
